/*************************************************************************
 *                    free                     *
 *************************************************************************
 *************************************************************************
 * Filename	   : table_pmt.h
 * Description   : This file is used to TODO
 * Version	   : 1.0
 * History       :
 free 2013-4-15  Create
 *************************************************************************/

#ifndef _TABLE_PMT_H_
#define _TABLE_PMT_H_

typedef struct stProgramElement
{
	unsigned int stream_type :8;
	unsigned int reserved1 :3;
	unsigned int elementary_PID :13;
	unsigned int reserved2 :4;
	unsigned int ES_info_length :12;
	struct stProgramElement *pstNext;
} PROGRAM_ELEMENT;

typedef struct stSectionPmt
{
	unsigned int table_id :8;
	unsigned int section_syntax_indicator :1;
	unsigned int reserved_future_use :1;
	unsigned int reserved1 :2;
	unsigned int section_length :12;
	unsigned int program_number :16;
	unsigned int reserved2 :2;
	unsigned int version_number :5;
	unsigned int current_next_indicator :1;
	unsigned int section_number :8;
	unsigned int last_section_number :8;
	unsigned int reserved3 :3;
	unsigned int PCR_PID :13;
	unsigned int reserved4 :4;
	unsigned int program_info_length :12;
	PROGRAM_ELEMENT *pstProgramElements;
	struct stSectionPmt *pstNext;
} SECTION_PMT;

typedef struct stPmtTableList
{
	SECTION_PMT *pstSectionPmt;
	struct stPmtTableList *pstNext;
} PMT_TABLELIST;

SECTION_PMT *GetTablePmt(FILE *pInputFile, long int liFirstPackageOffset, int iPackageLength, int iPackagePID);
void FreeTablePmt(SECTION_PMT **ppstSectionPmt);
void FreeTableListPmt(PMT_TABLELIST **ppstTableList);
SECTION_PMT *GetPmtByProgramNumber(PMT_TABLELIST *pstPmtTableList, int iProgramNumber);
PMT_TABLELIST *GetTableListPmt(SECTION_PAT *pstTablePat, FILE *pInputFile, long int liFirstPackageOffset, int iPackageLength);

#endif /* TABLE_PMT_H_ */
